package com.zhangyuji.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangyuji.entity.ShoppingCart;
import com.zhangyuji.entity.User;
import com.zhangyuji.mapper.ShoppingCartMapper;
import com.zhangyuji.service.ShoppingCartService;
import com.zhangyuji.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    @Resource
    private UserService userService;

    @Override
    public Long getUserId(String userPhone) {
        //根据手机号查询用户id
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(userPhone != null,User::getPhone,userPhone);
        User user = userService.getOne(queryWrapper);
        Long userId = user.getId();
        return userId;
    }
}
